#include "Comm.hpp"
#include "Fifo.hpp"

using namespace std;

int main()
{
    //1.获取key
    key_t key = GetShmKeyorDie();
    cout<< "ket is " << ToHex(key) << endl;

    //2.创建共享内存
    int shmid = GetShm(key,SIZE);
    cout<< "shmid " << shmid << endl;
    
    //3.将共享内存链接起来
    char* addr = (char*)ShmAttach(shmid);
    cout<< "Attah shm addr success, it is " << ToHex((uint64_t)addr) <<endl;

    //4.创建命名管道
    Fifo fifo(Path);
    Sync syn;
    syn.OpenWriteOrDie();

    for(char C = 'A';C <= 'Z'; C++)
    {
        addr[C-'A'] = C;
        sleep(1);
        syn.Wakeup();
    }

    ShmDetach(addr);
    std::cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;
    DeleteShm(shmid);
    
    return 0;
}